home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / Vk / VkComponent.z / VkComponent
Encoding:
Text File  |  2001-04-17  |  44.5 KB  |  1,123 lines

  1.  
  2.  
  3.  
  4. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      VkComponent - Abstract base class for all ViewKit components
  10.  
  11. IIIINNNNHHHHEEEERRRRIIIITTTTSSSS FFFFRRRROOOOMMMM
  12.      VkCallbackObject
  13.  
  14. HHHHEEEEAAAADDDDEEEERRRR FFFFIIIILLLLEEEE
  15.      #include <Vk/VkComponent.h>
  16.  
  17. PPPPUUUUBBBBLLLLIIIICCCC PPPPRRRROOOOTTTTOOOOCCCCOOOOLLLL SSSSUUUUMMMMMMMMAAAARRRRYYYY
  18.    DDDDiiiissssppppllllaaaayyyyiiiinnnngggg CCCCoooommmmppppoooonnnneeeennnnttttssss
  19.               virtual void show()
  20.               virtual void hide()
  21.               void manage()
  22.               void unmanage()
  23.  
  24.  
  25.    DDDDeeeessssttttrrrruuuuccccttttoooorrrr
  26.               virtual ~VkComponent()
  27.  
  28.  
  29.    AAAAcccccccceeeessssssss FFFFuuuunnnnccccttttiiiioooonnnnssss
  30.               char * name() const
  31.               virtual const char *className();
  32.               Widget baseWidget() const
  33.               virtual operator Widget();
  34.  
  35.  
  36.    AAAAcccccccceeeessssssss FFFFuuuunnnnccccttttiiiioooonnnnssss ---- VVVViiiieeeewwwwKKKKiiiitttt 2222....1111 oooonnnnllllyyyy
  37.               VkScreen *getScreen();
  38.  
  39.  
  40.    SSSSuuuuppppppppoooorrrrtttteeeedddd CCCCaaaallllllllbbbbaaaacccckkkkssss
  41.               static const char * const deleteCallback
  42.  
  43.  
  44.    UUUUttttiiiilllliiiittttyyyy FFFFuuuunnnnccccttttiiiioooonnnnssss
  45.               virtual Boolean okToQuit()
  46.               virtual void    afterRealizeHook()
  47.               static  Boolean isComponent(VkComponent *comp)
  48.  
  49.  
  50.    DDDDyyyynnnnaaaammmmiiiicccc LLLLooooaaaaddddiiiinnnngggg SSSSuuuuppppppppoooorrrrtttt
  51.               static VkComponent *loadObject(const char *name,
  52.                                     Widget parent,
  53.                                     const char *className,
  54.                                     const char *filename);
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  71.  
  72.  
  73.  
  74. CLASS DESCRIPTION
  75.      The VkComponent class is the basis of nearly all classes in the ViewKit.
  76.      This abstract class defines the basic protocol followed by all _c_o_m_p_o_n_e_n_t_s
  77.      in the ViewKit, as well as those created by application developers.  The
  78.      concept of a user interface component is the fundamental underlying idea
  79.      on which the ViewKit is based. A component is simply a C++ class that has
  80.      some semantics and a presentation. Nearly all classes in the ViewKit are
  81.      components, including VkApp, VkSimpleWindow, and so on. The ViewKit
  82.      provides many component classes, and encourages an approach to building
  83.      applications based on building application-specific components.
  84.      Developers generally write applications by writing and connecting new
  85.      components.
  86.  
  87. SSSSUUUUBBBBCCCCLLLLAAAASSSSSSSS PPPPRRRROOOOTTTTOOOOCCCCOOOOLLLL SSSSUUUUMMMMMMMMAAAARRRRYYYY
  88.    HHHHaaaannnnddddlllliiiinnnngggg WWWWiiiiddddggggeeeetttt DDDDeeeessssttttrrrruuuuccccttttiiiioooonnnn
  89.               void installDestroyHandler();
  90.               void removeDestroyHandler();
  91.               virtual void widgetDestroyed();
  92.  
  93.  
  94.    RRRReeeessssoooouuuurrrrcccceeee SSSSuuuuppppppppoooorrrrtttt
  95.               void setDefaultResources ( const Widget w ,
  96.                                          const String *resourceSpec );
  97.               void getResources ( const XtResourceList resources,
  98.                                   const int numResources);
  99.  
  100.  
  101.    DDDDaaaattttaaaa MMMMeeeemmmmbbbbeeeerrrrssss
  102.          char   *_name;
  103.          Widget  _baseWidget;
  104.          Widget& _w;
  105.  
  106.    CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  107.               VkComponent( const char *name );
  108.               VkComponent();
  109.  
  110.  
  111.  
  112.    DDDDeeeerrrriiiivvvviiiinnnngggg SSSSuuuubbbbccccllllaaaasssssssseeeessss
  113.      The VkComponent class is an abstract class whose primary purpose is to
  114.      support subclasses. The following are a set of guidelines for writing
  115.      components based on the VkComponent class.
  116.  
  117.           All classes derived from VkComponent (known as components) support
  118.           one or more widgets.  Widgets encapsulated by a component should
  119.           form a subtree below a single root widget.
  120.  
  121.           The root of the widget subtree created by a component is referred to
  122.           as the base widget of the object. The base widget must be created by
  123.           the derived class, and assigned to the _baseWidget member inherited
  124.           from the VkComponent class.
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  137.  
  138.  
  139.  
  140.           Components should usually create the base widget and all other
  141.           widgets in the class constructor. The constructor should manage all
  142.           widgets except the base widget, which should be left unmanaged. The
  143.           entire subtree represented by a component can be managed or
  144.           unmanaged using the member functions supported by VkComponent.
  145.  
  146.           All constructors should take at least two arguments, a widget to be
  147.           used as the parent of the component's base widget, and a string to
  148.           be used as the name of the base widget. The name argument should be
  149.           passed on to the VkComponent constructor, which makes a copy of the
  150.           string. All references to a component's name should use the __n_a_m_e
  151.           member inherited from VkComponent, or the _n_a_m_e() access function.
  152.  
  153.           All component classes should override the virtual _c_l_a_s_s_N_a_m_e() member
  154.           function, which is expected to return a string that identifies the
  155.           name of the class.  Components should define any Xt callbacks
  156.           required by the class as static member functions.  These functions
  157.           are normally declared in the private section of the class, because
  158.           they are seldom useful to derived classes.
  159.  
  160.           All Xt callback functions installed for Motif widgets should be
  161.           passed the _t_h_i_s pointer as client data.  Callback functions are
  162.           expected to retrieve this pointer, cast it to the expected object
  163.           type and call a corresponding member function. By convention, static
  164.           member functions used as callbacks have the same name as the member
  165.           function they call, with the word Callback appended. For example,
  166.           the static member function _s_t_a_r_t_C_a_l_l_b_a_c_k() calls the member function
  167.           _s_t_a_r_t().  Member functions called by static member functions are
  168.           often private, but may also be part of the public or subclass
  169.           protocol of the class. Occasionally it is useful to declare one of
  170.           these functions to be virtual, allowing derived classes to change
  171.           the function ultimately called as a result of a callback.
  172.  
  173.           Derived classes should call _i_n_s_t_a_l_l_D_e_s_t_r_o_y_H_a_n_d_l_e_r() immediately
  174.           after creating a component's base widget. This sets up callbacks
  175.           that handle certain unpleasant problems that can occur with regard
  176.           to widget destruction.
  177.  
  178.           Derived classes that need to specify default resources to function
  179.           correctly should call the function _s_e_t_D_e_f_a_u_l_t_R_e_s_o_u_r_c_e_s() with an
  180.           appropriate resource list before creating the component's base
  181.           widget.
  182.  
  183.           Derived classes that wish to initialize data members from values in
  184.           the resource database should define an appropriate resource
  185.           specification and call the function _g_e_t_R_e_s_o_u_r_c_e_s() immediately after
  186.           the _i_n_s_t_a_l_l_D_e_s_t_r_o_y_H_a_n_d_l_e_r() function.
  187.  
  188. FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNN DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNNSSSS
  189.    VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  203.  
  204.  
  205.  
  206.               VkComponent( const char *name );
  207.               VkComponent();
  208.  
  209.  
  210.           The VkComponent constructor initializes the baseWidget to NULL and
  211.           initializes the __n_a_m_e member of the object. If a string is given as
  212.           an argument to the constructor, this name is copied. Otherwise, the
  213.           component is given the temporary name "component". In any case, a
  214.           dynamically allocated string is assigned to the __n_a_m_e member. The
  215.           VkComponent constructor is declared to be protected and can only be
  216.           called from derived classes.
  217.  
  218.    iiiinnnnssssttttaaaallllllllDDDDeeeessssttttrrrrooooyyyyHHHHaaaannnnddddlllleeeerrrr
  219.               void installDestroyHandler();
  220.  
  221.  
  222.           This function should be called by derived class immediately after
  223.           the component's base widget is created. It registers an
  224.           XmNdestroyCallback function for the base widget that helps ensure
  225.           that the widget is not deleted out from under the object. When
  226.           linking with the debugging version of the ViewKit library, a warning
  227.           will be issued about any class that does not install a
  228.           destroyHandler.
  229.  
  230.    rrrreeeemmmmoooovvvveeeeDDDDeeeessssttttrrrrooooyyyyHHHHaaaannnnddddlllleeeerrrr
  231.               void removeDestroyHandler();
  232.  
  233.  
  234.           This function removes the destroy callback installed by
  235.           _i_n_s_t_a_l_l_D_e_s_t_r_o_y_H_a_n_d_l_e_r(). Occasionally, it may be necessary to
  236.           disable the destroy callback. The VkComponent class removes the
  237.           callback in the destructor before destroying the widget, to prevent
  238.           referencing an object after it has been deleted.
  239.  
  240.    wwwwiiiiddddggggeeeettttDDDDeeeessssttttrrrrooooyyyyeeeedddd
  241.               virtual void widgetDestroyed();
  242.  
  243.  
  244.           This virtual function is called when a component's base widget is
  245.           destroyed. The default VkComponent member function simply NULL's the
  246.           __b_a_s_e_W_i_d_g_e_t member. Derived classes may override this function is
  247.           additional tasks need to be performed in the event of widget
  248.           destruction.  However, they should always call their base class's
  249.           method as well.
  250.  
  251.    sssseeeettttDDDDeeeeffffaaaauuuullllttttRRRReeeessssoooouuuurrrrcccceeeessss
  252.               void setDefaultResources ( const Widget w,
  253.                                          const String *resourceSpec );
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  269.  
  270.  
  271.  
  272.           This member function can be called to store a collection of
  273.           resources in the application's resource database. This is usually
  274.           done to associate a set of resources with all instances of a class
  275.           automatically. Resources are loaded with the lowest precedence, so
  276.           that these resources are true defaults. They can be overridden
  277.           easily in any resource file.
  278.  
  279.           The _s_e_t_D_e_f_a_u_l_t_R_e_s_o_u_r_c_e_s() function should be called in the
  280.           constructor, before creating the base widget, and with the parent
  281.           argument to the component as the first argument. The second argument
  282.           must be a NULL-terminated array of strings, written in the style of
  283.           an X resource database specification. All resources should be
  284.           written as if they applied to all widgets below the base widget.
  285.           When resources are loaded, the value of __n_a_m_e is prepended to all
  286.           entries, unless that entry begins with the "-" or '+' character. A
  287.           leading '-' arranges for the resources to be specified relative to
  288.           the base widget, and reduces the chances of name space collisions. A
  289.           leading "+" adds the class name of the application to the resource
  290.           specification. This is useful for overriding resources set by SGI
  291.           Schemes, which are automatically qualified by the application's
  292.           class name, without requiring the component to be tied to a specific
  293.           application in advance.
  294.  
  295.           For example, the following code segment specifies a default label
  296.           string of the "pushButton" widget. The resources also specify that
  297.           the resource string "*sampleExists: TRUE" should be added to the
  298.           resource database without qualifying the resource any further (i.e.
  299.           do not prepend __n_a_m_e). This is useful in rare situations where it is
  300.           desirable to add global resources to the database.
  301.  
  302.  
  303.            String  SampleComponent::_defaultResources[] = {
  304.                   "*pushbutton.labelString:  Push Me",
  305.                   "-*sampleExists:  TRUE",
  306.                   NULL
  307.            };
  308.            SampleComponent::SampleComponent(const char *name,
  309.                                            Widget parent) :
  310.                   VkComponent(name)
  311.            {
  312.               // Load any class-defaulted resources
  313.               // for this object
  314.  
  315.               setDefaultResources(parent, _defaultResources  );
  316.  
  317.               // Create an unmanaged widget as the top of
  318.               // the widget hierarchy
  319.  
  320.               _baseWidget =  XtVaCreateWidget ( _name,
  321.                                                 xmRowColumnWidgetClass,
  322.                                                 parent,
  323.                                                 NULL ) ;
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  335.  
  336.  
  337.  
  338.               // install a callback to guard against
  339.               // unexpected widget destruction
  340.  
  341.               installDestroyHandler();
  342.  
  343.               _pushButton = XmCreatePushButton( _baseWidget,
  344.                                                 "pushbutton",
  345.                                                  NULL, 0)
  346.  
  347.               // ...
  348.  
  349.  
  350.  
  351.    ggggeeeettttRRRReeeessssoooouuuurrrrcccceeeessss
  352.               void getResources ( const XtResourceList resources,
  353.                                   const int numResources );
  354.  
  355.  
  356.           This member function can be used in conjunction with an XtResource
  357.           list to initialize members of a specific class from values retrieved
  358.           from the resource database. It must be called _a_f_t_e_r the base widget
  359.           has been created.
  360.  
  361.           For example, the following code segments demonstrate the
  362.           initialization of a data member, __v_e_r_b_o_s_e, from the resource data
  363.           base. Default values are specified in the XtResource structure, but
  364.           the ultimate value is determined by the value of the resource named
  365.           "verbose" in the resource database.
  366.  
  367.  
  368.            // Header file
  369.  
  370.            class SampleComponent : public VkComponent
  371.            {
  372.               private:
  373.  
  374.                static XtResource _resources[];
  375.  
  376.               protected:
  377.  
  378.                Boolean _verbose;
  379.  
  380.             public:
  381.  
  382.               SampleComponent(const char *, Widget);
  383.            };
  384.  
  385.            // Source file
  386.  
  387.            #include "SampleComponent.h"
  388.  
  389.            XtResource SampleComponent::_resources [] = {
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  401.  
  402.  
  403.  
  404.            {
  405.                "verbose",
  406.                "Verbose",
  407.                XmRBoolean,
  408.                sizeof ( Boolean ),
  409.                XtOffset ( SampleComponent *, _verbose ),
  410.                XmRString,
  411.                (XtPointer) "FALSE",
  412.              },
  413.            };
  414.  
  415.  
  416.  
  417.            SampleComponent::SampleComponent(Widget parent,
  418.                                             const char *name) :
  419.                     VkComponent (name)
  420.            {
  421.               // Create an unmanaged widget as the
  422.               // top of the widget hierarchy
  423.  
  424.               _baseWidget =  XtVaCreateWidget ( _name,
  425.                                                 xmFrameWidgetClass,
  426.                                                 parent,
  427.                                                 NULL ) ;
  428.  
  429.               // install a callback to guard against
  430.               // unexpected widget destruction
  431.  
  432.               installDestroyHandler();
  433.  
  434.               // Initialize members from resource database
  435.  
  436.               getResources ( _resources, XtNumber(_resources) );
  437.  
  438.               // ...
  439.            }
  440.  
  441.  
  442.  
  443.    ____nnnnaaaammmmeeee
  444.               char   *_name;
  445.  
  446.  
  447.           All components are expected to have a unique name, which is
  448.           maintained by VkComponent as the __n_a_m_e data member. This member must
  449.           be used as the name of the base widget for the resource support to
  450.           work correctly.
  451.  
  452.    ____bbbbaaaasssseeeeWWWWiiiiddddggggeeeetttt
  453.               Widget  _baseWidget;
  454.               Widget& _w;
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  467.  
  468.  
  469.  
  470.           Many functions and other components rely on the existence of a "base
  471.           widget" for all components. The base widget is the widget at the top
  472.           of the widget tree for the component. This widget should be assigned
  473.           to __b_a_s_e_W_i_d_g_e_t when it is created. The data member __w is a reference
  474.           to the __b_a_s_e_W_i_d_g_e_t member and exists only for historical reasons.
  475.  
  476.    sssshhhhoooowwww(((())))
  477.               virtual void show();
  478.  
  479.  
  480.           This member function should be called to display the widgets in a
  481.           component. The _s_h_o_w() member function must be called initially to
  482.           display the widgets, and may be called after _h_i_d_e() has been called
  483.           to redisplay the component. In the simplest case, _s_h_o_w() is
  484.           analogous to calling _X_t_M_a_n_a_g_e_C_h_i_l_d() on the base Widget of the
  485.           component. NNNNooootttteeee tttthhhhaaaatttt XXXXttttMMMMaaaannnnaaaaggggeeeeCCCChhhhiiiilllldddd(((()))) sssshhhhoooouuuulllldddd nnnneeeevvvveeeerrrr bbbbeeee ccccaaaalllllllleeeedddd
  486.           eeeexxxxpppplllliiiicccciiiittttllllyyyy oooonnnn tttthhhheeee bbbbaaaasssseeee wwwwiiiiddddggggeeeetttt. Conceptually, _s_h_o_w() does whatever is
  487.           required to display a component, which may involve more than simply
  488.           managing widgets. _S_h_o_w() is a higher level of abstraction for the
  489.           total set of operations required to make a user interface component
  490.           visible.
  491.  
  492.    hhhhiiiiddddeeee
  493.               virtual void hide();
  494.  
  495.  
  496.           This member function causes a component to disappear from the
  497.           screen.  Like _s_h_o_w(), _h_i_d_e() is analogous to
  498.           _X_t_U_n_m_a_n_a_g_e_C_h_i_l_d(__b_a_s_e_W_i_d_g_e_t). However, it is a higher level
  499.           abstraction that individual classes may implement differently in
  500.           order to perform whatever actions are necessary to remove a
  501.           component from the visible screen.
  502.  
  503.    mmmmaaaannnnaaaaggggeeee(((())))
  504.    uuuunnnnmmmmaaaannnnaaaaggggeeee(((())))
  505.               void manage() ;
  506.               void unmanage();
  507.  
  508.  
  509.           _M_a_n_a_g_e() and _u_n_m_a_n_a_g_e() simply call _s_h_o_w() and _h_i_d_e(), respectively.
  510.           These functions exist for compatibility with earlier versions of
  511.           this class.
  512.  
  513.    nnnnaaaammmmeeee(((())))
  514.             const char * name() const
  515.  
  516.  
  517.           Returns the instance name of a component object.
  518.  
  519.    ccccllllaaaassssssssNNNNaaaammmmeeee
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  533.  
  534.  
  535.  
  536.            virtual const char *className();
  537.  
  538.  
  539.           Returns the name of the class to which the component belongs. Each
  540.           subclass of VkComponent is expected to override this function. The
  541.           class name is used by various ViewKit facilities. The class name for
  542.           the VkComponent class is "VkComponent".
  543.  
  544.    bbbbaaaasssseeeeWWWWiiiiddddggggeeeetttt
  545.            Widget baseWidget() const { return _baseWidget; }
  546.  
  547.  
  548.           This access function returns the base widget of a component.
  549.           Normally, components are as encapsulated as possible, and
  550.           programmers should avoid operating directly on a component's base
  551.           widget outside the class. However, certain operations may require
  552.           access to a component's base widget. For example, after
  553.           instantiating a component as a child of an XmForm widget, it may be
  554.           necessary to set various constraint resources.
  555.  
  556.    ggggeeeettttSSSSccccrrrreeeeeeeennnn(((()))) ---- VVVViiiieeeewwwwKKKKiiiitttt 2222....1111 oooonnnnllllyyyy
  557.            VkScreen *getScreen();
  558.  
  559.  
  560.           Returns the VkScreen object associated with this component.
  561.  
  562.    ooooppppeeeerrrraaaattttoooorrrr WWWWiiiiddddggggeeeetttt
  563.            virtual operator Widget();
  564.  
  565.  
  566.           The operator _W_i_d_g_e_t allows a VkComponent object to be passed
  567.           directly to functions that expect a widget. By default, the operator
  568.           converts the component into its base widget. Some derived classes
  569.           may override this operator to return a different widget. Note that
  570.           the object itself and not a pointer to the object must be used.
  571.  
  572.           For example, assume that SampleComponent is a class derived from
  573.           VkComponent. We could do something like this:
  574.  
  575.  
  576.             Widget form = XmCreateForm(parent,
  577.                                        "form",
  578.                                         NULL, 0);
  579.             SampleComponent *sc = new SampleComponent(form,
  580.                                                       "sample");
  581.             XtVaSetValues(*sc,
  582.                            XmNtopAttachment, XmATTACH_FORM,
  583.                            NULL);
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  599.  
  600.  
  601.  
  602.           The _W_i_d_g_e_t operator is used in this example as a result of the
  603.           implicit cast done to the *sc variable since _X_t_V_a_S_e_t_V_a_l_u_e_s() expects
  604.           a parameter of type _W_i_d_g_e_t as its first argument.
  605.  
  606.    ddddeeeelllleeeetttteeeeCCCCaaaallllllllbbbbaaaacccckkkk
  607.             static const char * const deleteCallback;
  608.  
  609.  
  610.           This string identifies the name of a ViewKit member function
  611.           callback supported by all classes derived from VkComponent.
  612.  
  613.    ooookkkkTTTTooooQQQQuuuuiiiitttt
  614.             virtual Boolean okToQuit();
  615.  
  616.  
  617.           This function can be used to support "safe quit" mechanisms. In
  618.           general, this method is only used by VkSimpleWindow and subclasses
  619.           (See VkApp(3X)and VkSimpleWindow(3X)). When _V_k_A_p_p::_q_u_i_t_Y_o_u_r_s_e_l_f() is
  620.           called, VkApp checks all registered windows before quitting, If any
  621.           window's method returns FALSE, the application does not exit. Some
  622.           windows may wish to check components contained within that window.
  623.           _O_k_T_o_Q_u_i_t() provides a standard way to perform this check. By default
  624.           _o_k_T_o_Q_u_i_t() returns TRUE. If any component, including a
  625.           VkSimpleWindow wishes to check with other objects, it arrange to
  626.           call the _o_k_T_o_Q_u_i_t() functions of contained components and implement
  627.           the desired logic. The ViewKit only calls this method for
  628.           VkSimpleWindow (and derived classes).
  629.  
  630.    aaaafffftttteeeerrrrRRRReeeeaaaalllliiiizzzzeeeeHHHHooooooookkkk
  631.             virtual void afterRealizeHook();
  632.  
  633.  
  634.           Some components need to know when widgets in the component have been
  635.           realized (i.e. a window exists for the widget), or when the widgets
  636.           have been set to their final size. This virtual function is called
  637.           in response to the first MapNotify event received for the base
  638.           widget of a component.  At this point, all windows have been created
  639.           and the widgets have just become visible.
  640.  
  641.    iiiissssCCCCoooommmmppppoooonnnneeeennnntttt
  642.             static Boolean isComponent(VkComponent *comp);
  643.  
  644.  
  645.           This function applies certain heuristics to determine whether a
  646.           given pointer represents a valid VkComponent object. If a pointer
  647.           points to a VkComponent that has not been deleted, this function
  648.           will always return TRUE. Otherwise the function returns FALSE. It is
  649.           possible, although highly unlikely, that this function could
  650.           mistakenly identify a dangling pointer to a deleted object as a
  651.           valid object. This could happen if another component were to be
  652.           allocated at exactly the same address as the deleted object a
  653.           pointer previously pointed to.
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  665.  
  666.  
  667.  
  668. DDDDYYYYNNNNAAAAMMMMIIIICCCC LLLLOOOOAAAADDDDIIIINNNNGGGG
  669.      ViewKit supports the ability to dynamically load a class from a dynamic
  670.      shared object or library. To participate in this scheme, a VkComponent
  671.      subclass must provide a few hooks, using specific conventions. Classes
  672.      created with RapidApp(TM) are automatically set up for dynamic loading.
  673.      To prepare a class by hand, you must provide a creation function, and an
  674.      optional _I_n_t_e_r_f_a_c_e _M_a_p. (See VkCallbackObject).
  675.  
  676.           A creation function is a static member function that creates an
  677.           instance of the associated class. The creation function must be
  678.           named Create<ClassName>, where <ClassName> is the name of the class,
  679.           and must take two arguments, the name of the instance and a parent
  680.           widget.  The class is expected to instantiate an object and return
  681.           it as a VkComponent*. For example, a class LabeledText would have a
  682.           declaration in its header:
  683.  
  684.  
  685.           static VkComponent *CreateLabeledText(const char *name, Widget parent);
  686.  
  687.  
  688.  
  689.           and then in the source file:
  690.  
  691.  
  692.           VkComponent *LabeledText::CreateLabeledText(const char *name, Widget parent)
  693.           {
  694.              LabeledText *obj = new LabeledText(name, parent);
  695.  
  696.              return obj;
  697.           }
  698.  
  699.  
  700.  
  701.    llllooooaaaaddddOOOObbbbjjjjeeeecccctttt
  702.               static VkComponent *loadObject(const char *name,
  703.                                  Widget parent,
  704.                                  const char *className,
  705.                                  const char *filename);
  706.  
  707.  
  708.  
  709.           If a component has the creation member function described above, it
  710.           can be loaded by calling VkComponent::loadObject, with an instance
  711.           name, parent widget, name of the class to be instantiated, and the
  712.           name of a file in which the object is located. For example, a class
  713.           LabeledText, which is found in a shared library named liblbtext.so,
  714.           can be loaded as:
  715.  
  716.  
  717.            LabeledText *lb = VkComponent::loadObject("labeledtext",
  718.                                       parent,
  719.                                          "LabeledText",
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  731.  
  732.  
  733.  
  734.                                  "liblbtext.so");
  735.  
  736.  
  737.  
  738.  
  739. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  740.      The following example component implements a very simple color selector
  741.      that allows users to select from three colors, red, green, or blue. The
  742.      component supports toggle buttons for each of these colors.  All toggle
  743.      buttons are in a radio box widget, so that only one can be selected at a
  744.      time. The class installs callbacks for each toggle button, which
  745.      eventually call the virtual function _c_o_l_o_r_C_h_a_n_g_e_d().
  746.  
  747.      Applications can choose to use this class in one of two ways.
  748.  
  749.           First, the member function _c_o_l_o_r_C_h_a_n_g_e_d() is declared to be virtual,
  750.           so applications could incorporate this component by creating a
  751.           subclass. This choice is attractive when the application needs to
  752.           perform additional work when a toggle is selected, or when the
  753.           component needs to be expanded or modified in some way.
  754.  
  755.           Second, applications might choose to use the _c_o_l_o_r_C_h_a_n_g_e_d_C_a_l_l_b_a_c_k()
  756.           supported by the ColorChoice class to call a member function of
  757.           another object when a color is selected.  This option is most
  758.           appropriate when the class already has the desired functionality and
  759.           when trying to avoid the additional work required to write a
  760.           subclass.
  761.  
  762.  
  763.            //////////////////////////////////////////////////////////////
  764.            //
  765.            // Header file for ColorChoice
  766.            //////////////////////////////////////////////////////////////
  767.            #ifndef _COLORCHOICE_H
  768.            #define _COLORCHOICE_H
  769.            #include <Vk/VkComponent.h>
  770.  
  771.            class ColorChoice : public VkComponent
  772.            {
  773.  
  774.             private:
  775.  
  776.               // Array that describes interactions with
  777.               // Xt resource manager
  778.  
  779.               static String  _defaultColorChoiceResources[];
  780.  
  781.               // Callbacks to interface with Motif
  782.  
  783.               static void newColorCallback (Widget,
  784.                                             XtPointer,
  785.                                             XtPointer);
  786.  
  787.  
  788.  
  789.                                                                        PPPPaaaaggggeeee 11112222
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  797.  
  798.  
  799.  
  800.             protected:
  801.  
  802.               // Widgets created by this class
  803.  
  804.               Widget  _blue;
  805.               Widget  _green;
  806.               Widget  _radioBox;
  807.               Widget  _red;
  808.  
  809.               virtual void newColor ( Widget, XtPointer );
  810.  
  811.             public:
  812.  
  813.               ColorChoice(const char *, Widget);
  814.               ~ColorChoice();
  815.               const char* className();
  816.  
  817.               static const char * const colorChangedCallback;
  818.               enum Color { RED, GREEN, BLUE };
  819.            };
  820.            #endif
  821.  
  822.            /////////////////////////////////////////////////////////////
  823.            //
  824.            // Source file for ColorChoice
  825.            /////////////////////////////////////////////////////////////
  826.            #include "ColorChoice.h
  827.            #include <Xm/Frame.h>
  828.            #include <Xm/RowColumn.h>
  829.            #include <Xm/ToggleB.h>
  830.  
  831.            // These are default resources for widgets in objects
  832.            // of this class All resources will be prepended by
  833.            // *<name> at instantiation, where <name> is the name
  834.            // of the specific instance, as well as the name of
  835.            // the baseWidget. These are only defaults, and may be
  836.            // overridden in a resource file by providing a more
  837.            // specific resource name
  838.  
  839.            String ColorChoice::_defaultColorChoiceResources[]={
  840.                   "*red.labelString:  Red",
  841.                   "*green.labelString:  Green",
  842.                   "*blue.labelString:  Blue",
  843.                   NULL
  844.            };
  845.  
  846.            const char * const ColorChoice::colorChangedCallback = "colorChanged";
  847.  
  848.            ColorChoice::ColorChoice(const char *name,
  849.                                     Widget parent) : VkComponent(name)
  850.            {
  851.               // Load any class-defaulted resources
  852.  
  853.  
  854.  
  855.                                                                        PPPPaaaaggggeeee 11113333
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  863.  
  864.  
  865.  
  866.               // for this object
  867.  
  868.               setDefaultResources(parent,
  869.                                   _defaultColorChoiceResources );
  870.  
  871.               // Create an unmanaged widget as the top
  872.               // of the widget hierarchy
  873.  
  874.               _baseWidget =  XtVaCreateWidget ( _name,
  875.                                                 xmFrameWidgetClass,
  876.                                                 parent,
  877.                                                 NULL ) ;
  878.  
  879.               // install a callback to guard against
  880.               // unexpected widget destruction
  881.  
  882.               installDestroyHandler();
  883.  
  884.  
  885.               // Create widgets used in this component
  886.               // All variables are data members of this class
  887.  
  888.               _radioBox = XmCreateRadioBox( _baseWidget,
  889.                                             "radioBox",
  890.                                             NULL, 0 );
  891.               XtManageChild( _radioBox );
  892.  
  893.  
  894.               _red = XtVaCreateManagedWidget  ( "red",
  895.                                         xmToggleButtonWidgetClass,
  896.                                         _radioBox,
  897.                                         NULL ) ;
  898.  
  899.               XtAddCallback ( _red,
  900.                               XmNvalueChangedCallback,
  901.                               &ColorChoice::newColorCallback,
  902.                               (XtPointer) this );
  903.  
  904.               _green = XtVaCreateManagedWidget  ( "green",
  905.                                         xmToggleButtonWidgetClass,
  906.                                         _radioBox,
  907.                                         NULL ) ;
  908.  
  909.               XtAddCallback ( _green,
  910.                               XmNvalueChangedCallback,
  911.                               &ColorChoice::newColorCallback,
  912.                               (XtPointer) this );
  913.  
  914.               _blue = XtVaCreateManagedWidget  ( "blue",
  915.                                                 xmToggleButtonWidgetClass,
  916.                                                 _radioBox,
  917.                                                 XmNset, TRUE,
  918.  
  919.  
  920.  
  921.                                                                        PPPPaaaaggggeeee 11114444
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  929.  
  930.  
  931.  
  932.                                                 NULL ) ;
  933.               XtAddCallback ( _blue,
  934.                                XmNvalueChangedCallback,
  935.                                &ColorChoice::newColorCallback,
  936.                                (XtPointer) this );
  937.            }
  938.  
  939.            ColorChoice::~ColorChoice()
  940.            {
  941.               // Empty Destructor. Base class destroys widgets
  942.            }
  943.  
  944.            const char* ColorChoice::className()
  945.            {
  946.               return ("ColorChoice");
  947.            }
  948.  
  949.            void ColorChoice::newColorCallback (Widget w,
  950.                                       XtPointer clientData,
  951.                                       XtPointer callData)
  952.            {
  953.               ColorChoice* obj = (ColorChoice*) clientData;
  954.  
  955.               obj->newColor(w, callData);
  956.            }
  957.  
  958.            void ColorChoice::newColor(Widget w,
  959.                                       XtPointer callData )
  960.            {
  961.               Color chosenColor;
  962.               XmToggleButtonCallbackStruct *cbs =
  963.                    (XmToggleButtonCallbackStruct*) callData;
  964.  
  965.               if(cbs->set)
  966.               {
  967.                   if(w == _red) chosenColor = RED;
  968.                   else if(w == _blue) chosenColor = BLUE;
  969.                   else if(w == _green) chosenColor = GREEN;
  970.  
  971.                   callCallbacks(colorChangedCallback,
  972.                                 (void *) chosenColor);
  973.               }
  974.            }
  975.  
  976.  
  977.  
  978.    AAAA SSSSuuuubbbbccccllllaaaassssssssiiiinnnngggg EEEExxxxaaaammmmpppplllleeee
  979.      The following example illustrates how subclassing can be used to modify
  980.      the behavior of a component. This example changes the ColorChoice
  981.      component shown above by allowing multiple colors to be chosen at once.
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                                                        PPPPaaaaggggeeee 11115555
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  995.  
  996.  
  997.  
  998.            //////////////////////////////////////////////////////////////
  999.            // Header file for ColorChoices a subclass template
  1000.            //////////////////////////////////////////////////////////////
  1001.            #ifndef _COLORCHOICES_H
  1002.            #define _COLORCHOICES_H
  1003.  
  1004.            #include "ColorChoice.h"
  1005.  
  1006.            class ColorChoices : public ColorChoice
  1007.            {
  1008.  
  1009.             protected:
  1010.  
  1011.             public:
  1012.  
  1013.               ColorChoices(const char *, Widget);
  1014.               ~ColorChoices();
  1015.               const char* className();
  1016.            };
  1017.            #endif
  1018.  
  1019.            /////////////////////////////////////////////////////////////
  1020.            // Source file for ColorChoices
  1021.            /////////////////////////////////////////////////////////////
  1022.  
  1023.            #include "ColorChoices.h"
  1024.  
  1025.            ColorChoices::ColorChoices(const char *name,
  1026.                                       Widget parent) :
  1027.                    ColorChoice(name, parent)
  1028.            {
  1029.                   XtVaSetValues(_radioBox, XmNradioBehavior, FALSE, NULL);
  1030.            }
  1031.  
  1032.            ColorChoices::~ColorChoices()
  1033.            {
  1034.                // Empty
  1035.             }
  1036.  
  1037.            const char* ColorChoices::className()
  1038.            {
  1039.               return ("ColorChoices");
  1040.            }
  1041.  
  1042.  
  1043. IIIINNNNHHHHEEEERRRRIIIITTTTEEEEDDDD MMMMEEEEMMMMBBBBEEEERRRR FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNNSSSS
  1044.    IIIInnnnhhhheeeerrrriiiitttteeeedddd ffffrrrroooommmm VVVVkkkkCCCCaaaallllllllbbbbaaaacccckkkkOOOObbbbjjjjeeeecccctttt
  1045.           callCallbacks(), addCallback(), removeCallback(),
  1046.           removeAllCallbacks()
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.                                                                        PPPPaaaaggggeeee 11116666
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))                                                VVVVkkkkCCCCoooommmmppppoooonnnneeeennnntttt((((3333xxxx))))
  1061.  
  1062.  
  1063.  
  1064. KKKKNNNNOOOOWWWWNNNN DDDDEEEERRRRIIIIVVVVEEEEDDDD CCCCLLLLAAAASSSSSSSSEEEESSSS
  1065.      VkComponentList, VkApp, VkMsgApp, VkSimpleWindow, VkWindow, VkForkDoc,
  1066.      VkMsgWindow, VkDialogManager, VkBusyDialog, VkInterruptDialog,
  1067.      VkErrorDialog, VkFatalErrorDialog, VkFileSelectionDialog,
  1068.      VkWarningDialog, VkGenericDialog, VkPrefDialog, VkInfoDialog,
  1069.      VkQuestionDialog, VkToggleList, VkMenuItem, VkMenuAction,
  1070.      VkMenuConfirmFirstAction, VkMenuActionObject, VkMenuActionWidget,
  1071.      VkMenuToggle, VkMenuUndoManager, VkMenuLabel, VkMenuSeparator, VkMenu,
  1072.      VkOptionMenu, VkSubMenu, VkHelpPane, VkRadioSubMenu, VkMenuBar,
  1073.      VkPopupMenu, VkTextIO, VkForkIO, VkCheckBox, VkRadioBox,
  1074.      VkCompletionField, VkDoubleBuffer, VkMeter, VkPie, VkDropSite, VkGraph,
  1075.      VkNode, VkPeriodic, VkOutline, VkOutlineASB, VkPackTight, VkPrefItem,
  1076.      VkPrefGroup, VkPrefList, VkPrefRadio, VkPrefText, VkPrefToggle,
  1077.      VkPrefOption, VkPrefCustom, VkPrefEmpty, VkPrefLabel, VkPrefSeparator,
  1078.      VkRepeatButton, VkResizer, VkScroll, VkMsgComponent
  1079.  
  1080. BBBBUUUUGGGGSSSS
  1081. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  1082.      VkCallbackObject, VkComponentList
  1083.      _V_i_e_w_K_i_t _P_r_o_g_r_a_m_m_e_r'_s _G_u_i_d_e
  1084.      _T_h_e _X _W_i_n_d_o_w _S_y_s_t_e_m, DEC Press, Bob Sheifler and Jim Gettys
  1085.      _T_h_e _X _W_i_n_d_o_w _S_y_s_t_e_m _T_o_o_l_k_i_t, DEC Press, Paul Asente and Ralph Swick
  1086.      _T_h_e _O_S_F/_M_o_t_i_f _P_r_o_g_r_a_m_m_e_r_s _R_e_f_e_r_e_n_c_e, Prentice Hall, OSF
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                                                        PPPPaaaaggggeeee 11117777
  1120.  
  1121.  
  1122.  
  1123.